<template>
    <rx-dialog  @close="cancel" @confirm="ok">
        <rx-vue-map
            v-if="mapConf"
            ref="map"
            v-model="curValue"
            :type="type"
            :config="mapConf"
            :showSearch="true"
        >
        </rx-vue-map>
    </rx-dialog>
</template>

<script>
import RxDialog from "../RxDialog.vue";
import mapConfig from "./mapConfig.js";
import RxVueMap from "@/components/MapViews/RxVueMap.vue";

export default {
    name: "RxMapDialog",
    components: {
        RxDialog,
        RxVueMap
    },
    mixins:[mapConfig],
    props: {
        dialogClose: Function,
        options:{},
        locations:{},
        center:{},
    },
    data() {
        return {
            curValue:"",
            type:this.options.mapType,//baidu amap
            mapConf:""
        }
    },
    created() {
        if(this.locations){
           this.curValue=this.locations;
        }
        this.init();
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "mapLang", key);
        },
        init(){
            this.setCenter(this.curValue);
            if(this.options.ak){
                let mapConf = this.type=='baidu'?this.baiduConfig:this.amapConfig;
                if(this.type=='baidu'){
                    mapConf.ak = this.options.ak;
                }else {
                    mapConf.key = this.options.ak;
                    mapConf.securityJsCode= this.options.secretKey;
                    window._AMapSecurityconfig = {
                        security3sCode: mapConf.securityJsCode
                    }
                }
                this.mapConf=mapConf;
            }else {
                this.$message.warning(this.i18n("mapKeyTip",'请联系管理员配置地图Key'));
            }
        },

        ok(){
            this.dialogClose({action: 'ok', data: this.curValue})
        },
        cancel(){
            this.dialogClose({})
        },

    },
    watch: {},
}
</script>

<style scoped>

</style>
